package edu.uow.devdocs
/**
 * The TimeTracker entity.
 *
 * @author    
 *
 *
 */
class TimeTracker {
    static mapping = {
         table 'TIME_TRACKER'
         // version is set to false, because this isn't available by default for legacy databases
         version false
         id column:'TIME_TRACKER_ID'
         project column:'SUB_SYSTEM_ID'
         phase column:'PHASE_ID'
         person column:'PERSON_ID'
         issue column:'ISSUE_ID'
         downtimeReport column:'DOWNTIME_REPORT_ID'
         developmentTask column:'DEVELOPMENT_TASK_ID'
         deployment column:'DEPLOYMENT_ID'
		 developmentChecklist column:"DEVELOPMENT_CHECKLIST_ID"
		 id generator: 'sequence', params:[sequence:'TIME_TRACKER_SEQ']
		 sort:['dateOfWork','desc']
    }

	Date dateOfWork = new Date()
    java.math.BigDecimal hours
    Date lastUpdated
    String comments
    // Relation
    Project project
    // Relation
    Phase phase
    // Relation
    Person person
    // Relation
    Issue issue
    // Relation
    DowntimeReport downtimeReport
    // Relation
    DevelopmentTask developmentTask
	DevelopmentChecklist developmentChecklist
    // Relation
    Deployment deployment
	java.math.BigDecimal taskId

    static constraints = {
        
		dateOfWork(nullable: false)
        hours(nullable: false, scale: 2, min: 0.25, max: 10.0)

        lastUpdated(nullable: true)
        comments(size: 0..2000)
        taskId(nullable: true, size: 0..20)
        project(nullable: false)
        phase(nullable: false)
        person()

        downtimeReport(nullable: true)
		issue(nullable: true)
        developmentTask(nullable: true)
		developmentChecklist(nullable: true)
        deployment(nullable: true)
    }
	
	static namedQueries = {
		totalHoursForProject { project ->
			eq('project',project)
			projections {
				sum('hours')
			}
			
		}
	}
	
	
    String toString() {
        return "person:${person?.username} date:${dateOfWork} hours:${hours} project:${project} phase:${phase} "
    }
}
